//
//  VolumeBrightnessView.m
//  GenericProject
//
//  Created by 皮蛋菌 on 2023/5/16.
//  Copyright © 2023 漠然丶情到深处. All rights reserved.
//

#import "VolumeBrightnessView.h"

@interface VolumeBrightnessView ()

@property(nonatomic,strong)UILabel *valueLabel;
@property(nonatomic,strong)UIProgressView *progressView;

@end

@implementation VolumeBrightnessView

- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        self.backgroundColor = [UIColor ls_colorWithHexString:@"000000" Alpha:0.4];
        [self createSubViews];
    }
    return self;
}

- (void)createSubViews {
    // 创建数值标签
    self.valueLabel = [[UILabel alloc] init];
    self.valueLabel.textAlignment = NSTextAlignmentCenter;
    self.valueLabel.textColor = [UIColor whiteColor];
    self.valueLabel.font = [UIFont systemFontOfSize:LSSYRealValue(12)];
    [self addSubview:self.valueLabel];
    [self.valueLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self).with.offset(0);
        make.left.equalTo(self).with.offset(0);
        make.size.mas_offset(CGSizeMake(LSSYRealValue(40), LSSYRealValue(20)));
    }];
    
    // 创建进度条
    self.progressView = [[UIProgressView alloc] init];
    self.progressView.progressTintColor = [UIColor greenColor];
    self.progressView.trackTintColor = [UIColor lightGrayColor];
    self.progressView.transform = CGAffineTransformMakeScale(1.0, 0.3);
    [self addSubview:self.progressView];
    [self.progressView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.valueLabel.mas_centerY);
        make.left.equalTo(self.valueLabel.mas_right).with.offset(LSSYRealValue(5));
        make.right.equalTo(self.mas_right).with.offset(LSSYRealValue(-10));
        make.height.mas_offset(LSSYRealValue(10));
    }];
}

- (void)setProgress:(CGFloat)progress {
    self.progressView.progress = progress;
    NSString *valueString = [NSString stringWithFormat:@"%.0f%%", progress * 100];
    self.valueLabel.text = valueString;
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
